#define  _CRT_SECURE_NO_WARNINGS 1
#include "game.h"
void InitBoard(char board[ROWS][COLS], int x, int y, char z)
{
	int i, j;
	for (i = 0; i < ROWS; i++)
	{
		for (j = 0; j < COLS; j++)
		{
			board[i][j] = z;
		}
	}

}
void Display(char board[ROWS][COLS], int x, int y)
{
	for (int a = 0; a <= x; a++)
	{
		printf("%d ", a);
	}
	printf("\n");
	for (int i = 1; i <= x; i++)
	{
		printf("%d ", i);
		for (int j = 1; j <= y; j++)
		{
			printf("%c ", board[i][j]);
		}
		printf("\n");
	}
}
void SetBoom(char mine[ROWS][COLS], int x, int y)
{
	int count = boom;
	while (count)
	{
		int a = rand() % 9 + 1;
		int b = rand() % 9 + 1;
		if (mine[a][b] == '0')
		{
			mine[a][b] = '1';
			count--;
		}
	}
}
int display_around(char mine[ROWS][COLS],int x,int y)
{
	return mine[x - 1][y - 1] + mine[x - 1][y + 1] + mine[x][y - 1] + mine[x][y + 1] + mine[x + 1][y - 1] + mine[x + 1][y + 1] + mine[x - 1][y] + mine[x + 1][y]-8 * '0';
}
void FindBoom(char mine[ROWS][COLS],char show[ROWS][COLS],int row,int col)
{
	int win = 0;
	while (win < row * col - boom)
	{
		printf("请输入坐标：\n");
		int m = 0, n = 0;
		scanf("%d %d", &m, &n);
		if (m >= 1 && m <= 9 && n >= 1 && n <= 9)
		{
			if (show[m][n] == '*')
			{
				if (mine[m][n] == '1')
				{
					printf("很可惜，你被炸死了\n");
					Display(mine, ROW, COL);
					break;
				}
				else
				{
					win++;
					int num = display_around(mine, m, n);
					show[m][n] = num + '0';
					Display(show, ROW, COL);

				}

			}
			else 
			{
				printf("坐标已被排查过，请重新输入\n");
			}

			
		}
		else
		{
			printf("输入有误，请重新输入：\n");
		}
		
	}
	if (win == row * col - boom)
	{
		printf("恭喜你，游戏胜利\n");
		Display(mine, ROW, COL);
	}
}
